<template>
	<view v-if="user">
		<view class="contents">
			<u-sticky>
				<view class="bg_fff">
					<u-tabs :list="list1" @click="tabClick"></u-tabs>
				</view>
			</u-sticky>
			<view class="contents-list" v-if="tabsIndex == 0">
				<view class="contents_ops" style="margin-top: 25rpx;">
					<view class="display_flex space_between padding_right_l">
						<fui-input class="field" label-class="font-color" :disabled="list.workName != ''" v-model="list.workName" label="单位名称:" />
						<view v-if="user.power==1 || user.power==2" class="com_list_more" @click.stop="workNameAction = !workNameAction" placeholder="请输入单位名称">
							<text style="font-size:32rpx;">更多</text> <up-icon name="list"></up-icon>
							<image class="com_list_more_icon" src="/static/icon/accomplish_icon.png" mode="widthFix" />
						</view>
					</view>
				</view>
				<view class="contents_ops" style="margin-top: 25rpx;">
					<view class="display_flex space_between padding_right_l">
						<fui-input class="field" label-class="font-color" v-model="list.address" label="单位地址:" placeholder="请输入单位地址" />
						<view v-if="list.address" class="com_list_more">
							<!-- <text style="font-size:32rpx;">更多</text> <up-icon name="list"></up-icon> -->
							<image class="com_list_more_icon" src="/static/icon/accomplish_icon.png" mode="widthFix" />
						</view>
					</view>
				</view>
			</view>
			<view class="contents-list" v-if="tabsIndex == 1">
				<view class="contents_ops" style="margin-top: 25rpx;">
					<view class="display_flex space_between padding_right_l">
						<fui-input class="field" label-class="font-color" v-model="list.unitDistrict" label="所属区域:" />
						<view v-if="list.unitDistrict" class="com_list_more">
							<image class="com_list_more_icon" src="/static/icon/accomplish_icon.png" mode="widthFix" />
						</view>
					</view>
				</view>
				<view class="contents_ops" style="margin-top: 25rpx;">
					<view class="display_flex space_between padding_right_l">
						<fui-input class="field" label-class="font-color" v-model="list.aa" :label-width="100" label="单位建筑面积:" />
						<view v-if="list.aa" class="com_list_more">
							<!-- <text style="font-size:32rpx;">更多</text> <up-icon name="list"></up-icon> -->
							<image class="com_list_more_icon" src="/static/icon/accomplish_icon.png" mode="widthFix" />
						</view>
					</view>
				</view>
				<view class="contents_ops" style="margin-top: 25rpx;">
					<view class="bg_box">
						<view class="label" style="padding: 30rpx;font-size: 30rpx;">
							单位经营类型:
						</view>
						<view style="display: flex;flex-wrap: wrap;margin-left: 20rpx;margin-top: 10rpx;">
							<uni-data-checkbox style="width: 100%;" class="checkbox" v-model="list.checked" :localdata="sex"></uni-data-checkbox>
						</view>
					</view>
				</view>
				<view class="contents_ops " style="margin-top: 25rpx;">
					<view class="display_flex space_between padding_right_l">
						<fui-input class="field" label-class="font-color" v-model="list.type" :label-width="100" label="土地规划类型:" />
						<view v-if="list.type" class="com_list_more">
							<image class="com_list_more_icon" src="/static/icon/accomplish_icon.png" mode="widthFix" />
						</view>
					</view>
				</view>
				<view class="contents_ops" style="margin-top: 25rpx;">
					<view class="display_flex space_between padding_right_l">
						<fui-input class="field" label-class="font-color" v-model="list.name" :label-width="120" label="安全负责人名字:" />
						<view v-if="list.name" class="com_list_more">
							<image class="com_list_more_icon" src="/static/icon/accomplish_icon.png" mode="widthFix" />
						</view>
					</view>
				</view>
				<view class="contents_ops" style="margin-top: 25rpx;">
					<view class="display_flex space_between padding_right_l">
						<fui-input class="field" label-class="font-color" v-model="list.mobile" :label-width="120" maxlength="11" type="number" label="负责人联系方式:" />
						<view v-if="list.mobile" class="com_list_more">
							<image class="com_list_more_icon" src="/static/icon/accomplish_icon.png" mode="widthFix" />
						</view>
					</view>
				</view>
				<view class="contents_ops" style="margin-top: 25rpx;">
					<view class="display_flex space_between padding_right_l">
						<fui-input class="field" label-class="font-color" v-model="list.personInCharge" :label-width="120" label="主要负责人:" />
						<view v-if="list.personInCharge" class="com_list_more">
							<image class="com_list_more_icon" src="/static/icon/accomplish_icon.png" mode="widthFix" />
						</view>
					</view>
				</view>
				<view class="contents_ops" style="margin-top: 25rpx;">
					<view class="display_flex space_between padding_right_l">
						<fui-input class="field" label-class="font-color" v-model="list.contactPersonInCharge" :label-width="120" maxlength="11" type="number" label="主要负责人联系方式:" />
						<view v-if="list.contactPersonInCharge" class="com_list_more">
							<image class="com_list_more_icon" src="/static/icon/accomplish_icon.png" mode="widthFix" />
						</view>
					</view>
				</view>
				<view class="contents_ops" style="margin-top: 25rpx;">
					<view class="display_flex space_between padding_right_l">
						<fui-input class="field" label-class="font-color" v-model="list.aa" :label-width="100" label="单位建筑面积:" />
						<view v-if="list.aa" class="com_list_more">
							<image class="com_list_more_icon" src="/static/icon/accomplish_icon.png" mode="widthFix" />
						</view>
					</view>
				</view>
				<view class="contents_ops" style="margin-top: 25rpx;">
					<view v-if="preset.pointBitmap" style="margin-top: 5rpx; margin-bottom: 5rpx;">
						<up-cell-group :border="false">
							<up-cell @click="onPreviewImgs(preset.pointBitmap)" title="点位图:" clickable :border="false">
								<template #value>
									<view v-if="user.power==1 || user.power==2" style="width: 170rpx; display: flex; align-items: center; justify-content:flex-end;" @click.stop="presetSelectShow(6)">
										<text>更多</text>
										<up-icon name="list"></up-icon>
										<image class="com_list_more_icon" src="/static/icon/accomplish_icon.png" mode="widthFix" />
									</view>
								</template>
							</up-cell>
						</up-cell-group>
					</view>
					<view v-if="!preset.pointBitmap" style="margin-top: 5rpx; margin-bottom: 5rpx;">
						<up-cell-group :border="false">
							<up-cell @click="addOps(8)" title="点位图:" clickable :border="false">
								<template #value>
									<view style="width: 100rpx; display: flex; align-items: center; justify-content: center;" @click.stop="addOps(8)">
										<text>上传</text> <up-icon name="arrow-right"></up-icon>
									</view>
								</template>
							</up-cell>
						</up-cell-group>
					</view>

				</view>
				<view class="contents_ops" style="margin-top: 25rpx;">

					<view v-if="preset.fireControlAcceptanceDocument" style="margin-top: 5rpx; margin-bottom: 5rpx;">
						<up-cell-group :border="false">
							<up-cell @click="onPreviewImgs(preset.fireControlAcceptanceDocument)" title="消防验收文件:" clickable :border="false">
								<template #value>
									<view v-if="user.power==1 || user.power==2" class="com_list_more" @click.stop="presetSelectShow(7)">
										<text>更多</text> <up-icon name="list"></up-icon>
										<image class="com_list_more_icon" src="/static/icon/accomplish_icon.png" mode="widthFix" />
									</view>
								</template>
							</up-cell>
						</up-cell-group>
					</view>

					<view v-if="!preset.fireControlAcceptanceDocument" style="margin-top: 5rpx; margin-bottom: 5rpx;">
						<up-cell-group :border="false">
							<up-cell @click="addOps(7)" title="消防验收文件:" clickable :border="false">
								<template #value>
									<view style="width: 100rpx; display: flex; align-items: center; justify-content: center;" @click.stop="addOps(7)">
										<text>上传</text> <up-icon name="arrow-right"></up-icon>
									</view>
								</template>
							</up-cell>
						</up-cell-group>
					</view>
				</view>
				<view class="padding_tb_normal">
					<view class="display_column" v-if="user.power == 1 || user.power == 2">
						<button class="btn80" @click="submit()">提交</button>
					</view>
				</view>
			</view>
			<view class="contents-list" v-if='tabsIndex == 2'>
				<view v-if="user.power==1||user.power==2" class="add_user" @click="openUserAdd()">
					添加+
				</view>
				<u-subsection :list="list2" @change="tab2Click" :current="userTabsIndex"></u-subsection>
				<view class="bg_fff" style="padding: 20rpx 0;">
					<view class="bg_fff com_width">
						<u-input type="text" placeholder="请输入搜索内容" v-model="serachVal" @blur="searchFun" />
					</view>
				</view>
				<view v-if="!1" class="bg_fff" style="padding: 20rpx 0;">
					<view class="bg_fff com_width">
						<button class="com_btn share_btn" :id="userTabsIndex" open-type="share" type="primary">
							邀请
						</button>
					</view>
				</view>
				<template v-if="userTabsIndex == 0">
					<view v-if="fireManList.length > 0" class="contents_fileman">
						<view v-if="user.power==1 || user.power==2">
							<up-action-sheet @close="showOpsAllByUser=false" closeOnClickOverlay cancelText="取消" closeOnClickAction safeAreaInsetBottom :actions="actList1" @select="userSelectClick" title="更多操作" :show="showOpsAllByUser"></up-action-sheet>
						</view>
						<up-list @scrolltolower="scrolltolower" height="60vh">
							<up-list-item v-for="(item, index) in fireManList" :key="index">
								<view class="line">
									<view v-if="item.nickname">
										<up-cell :title="item.nickname" :value="'单位:' + item.unitName" :border="false">
											<template #icon>
												<up-avatar shape="square" size="35" src="/static/icon/fileman.png" customStyle="margin: -3rpx 5rpx -3rpx 0"></up-avatar>
											</template>
										</up-cell>
									</view>
									<view v-else>
										<up-cell :title="'消防操作员：请设置用户名'">
											<template #icon>
												<up-avatar shape="square" size="35" src="/static/icon/fileman.png" customStyle="margin: -3rpx 5rpx -3rpx 0"></up-avatar>
											</template>
										</up-cell>
									</view>
									<view class="btn-list">
										<up-button v-if="item.signature" @click="onPreview(item.signature)" icon="edit-pen" shape style="width: 160rpx;" text="签字" class="btn-item"></up-button>
										<up-button v-else @click="onSignaturesFile(item.uuid)" icon="edit-pen" shape style="width: 180rpx;" text="未签字" class="btn-item"></up-button>
										<up-button v-if="item.certificate" @click="onPreviewImgs(item.certificate)" icon="bookmark" shape style="width: 160rpx;" text="证书" class="btn-item"></up-button>
										<up-button v-else @click="onLoadCertificatFile(item.uuid)" icon="bookmark" shape style="width: 180rpx;" text="证书为空" class="btn-item"></up-button>
										<up-button v-if="user.power==1 || user.power==2 || item.uuid==user.uuid" @click="onShowOpsAllByUser(item)" icon="list-dot" shape style="width: 160rpx;" text="更多" class="btn-item"></up-button>
									</view>
								</view>
							</up-list-item>
						</up-list>
					</view>
					<view v-else class="cc">
						暂无记录
					</view>
					<view style="width: 100rpx;height: 100rpx;" />
				</template>
				<template v-else>
					<view style="box-sizing: border-box;padding: 0 10rpx;">
						<view v-if="filemans.length > 0" class="contents_fileman">
							<view v-if="user.power==1 || user.power==2">
								<up-action-sheet @close="showOpsAllByUserdh=false" closeOnClickOverlay cancelText="取消" closeOnClickAction safeAreaInsetBottom :actions="actListdh1" @select="userSelectClick" title="更多操作" :show="showOpsAllByUserdh"></up-action-sheet>
							</view>
							<up-list @scrolltolower="scrolltolower" height="60vh">
								<up-list-item v-for="(item, index) in filemans" :key="index">
									<view class="line" style="margin-bottom:20rpx;">
										<view v-if="item.nickName">
											<up-cell :title="item.nickName" :border="false">
												<template #icon>
													<up-avatar shape="square" size="35" src="/static/icon/fileman.png" customStyle="margin: -3rpx 5rpx -3rpx 0"></up-avatar>
												</template>
											</up-cell>
										</view>
										<view class="btn-list">
											<up-button v-if="item.signature" @click="onPreview(item.signature)" icon="edit-pen" shape style="width: 160rpx;" text="签字"></up-button>
											<up-button v-if="item.certificate" @click="onPreviewImgs(item.certificate)" icon="bookmark" shape style="width: 160rpx;" text="证书"></up-button>
											<up-button v-if="!item.signature" @click="onSignaturesFile(item.uuid)" icon="edit-pen" shape style="width: 180rpx;" text="未签字"></up-button>
											<up-button v-if="!item.certificate" @click="onLoadCertificatFile(item.uuid)" icon="bookmark" shape style="width: 180rpx;" text="证书为空"></up-button>
											<up-button v-if="user.power==1 || user.power==2 || item.uuid==user.uuid" @click="onShowOpsAllByUserdh(item)" icon="list-dot" shape style="width: 160rpx;" text="更多"></up-button>
										</view>
									</view>
								</up-list-item>
							</up-list>
						</view>
						<view v-else class="cc">
							暂无记录
						</view>
					</view>
				</template>
			</view>
			<view class="contents-list" v-if="tabsIndex==3">
				<view class="ui-box">
					<view class="bg_fff" style="padding: 20rpx 0;">
						<view class="bg_fff com_width">
							<u-input type="text" placeholder="请输入搜索内容" @blur="searchFunInviter" />
						</view>
					</view>
					<view v-if="listInviter && listInviter.length>0">
						<view v-for="item in listInviter" class="contents_ops ui-item">
							<view class="row grid middle ui-content">
								<view class="col">
									<view>
										<text>用户：</text>
										<text>{{item.nickname}}</text>
									</view>
									<view>
										<text>邀请人：</text>
										<text>{{item.inviter}}</text>
									</view>
									<view>
										<text>{{item.userCreateTime}}</text>
									</view>
									<view>
										<text v-if="item.groupId==1">消防操作人员</text>
										<text v-else-if="item.groupId==2">动火操作人员</text>
										<text v-else>安全管理人员</text>
									</view>
								</view>
								<view class="col middle">
									<up-text v-if="item.inviterStatus==1" type="success" text="已同意"></up-text>
									<up-text v-else-if="item.inviterStatus==2" type="warning" text="已拒绝"></up-text>
									<view v-else class="row middle">
										<view class="bg_fff com_width" style="height:60rpx;">
											<up-button @click="setStatus(item,1)" type="primary" text="同意"></up-button>
										</view>
										<view class="bg_fff com_width" style="height:60rpx;">
											<up-button @click="setStatus(item,2)" type="error" text="拒绝"></up-button>
										</view>
									</view>
								</view>
							</view>
						</view>
					</view>
					<view v-else class="center">
						暂无记录
					</view>
				</view>
			</view>
		</view>
		<view>
			<u-action-sheet @close="showOpsAll=!showOpsAll" closeOnClickOverlay cancelText="取消" closeOnClickAction safeAreaInsetBottom :actions="[{id:1,name:'上传'},{id:2,name: '清空',color:'#fa3534'}]" @select="presetSelectClick" title="更多操作" :show="showOpsAll"></u-action-sheet>
		</view>
		<view>
			<u-action-sheet @close="workNameAction=!workNameAction" closeOnClickOverlay cancelText="取消" closeOnClickAction safeAreaInsetBottom :actions="[{id:1,name:'修改'}]" @select="showWorkNameAction" title="修改单位名称" :show="workNameAction"></u-action-sheet>
		</view>
		<view>
			<u-datetime-picker title="日期选择" :min-date="today" @confirm="onFireMaintenanceExpirationTime" :show="showFireMaintenanceExpirationTime" @cancel="showFireMaintenanceExpirationTime =!showFireMaintenanceExpirationTime" mode="date"></u-datetime-picker>
		</view>
		<view>
			<u-datetime-picker title="日期选择" :min-date="today" @confirm="onFireMaintenanceBeginTime" :show="showFireMaintenanceBeginTime" @cancel="showFireMaintenanceBeginTime =!showFireMaintenanceBeginTime" mode="date"></u-datetime-picker>
		</view>
		<view class="canvas_box" v-if="showSignatureFile">
			<view class="can_content">
				<view style="width: 750rpx ;height: 750rpx;">
					<l-signature disableScroll ref="signatureRefNew" :penColor="penColor" :penSize="penSize" :openSmooth="openSmooth"></l-signature>
				</view>
				<view class="display_flex btn-box">
					<up-button type="primary" @click="showSignatureFile=false" :plain="true" text="取消"></up-button>
					<up-button type="primary" @click="onSignaturesFileSon" text="确认"></up-button>
				</view>
			</view>
		</view>
		<view>
			<u-modal @confirm="addOps(3)" @cancel="showSignatureUserUnit = !showSignatureUserUnit" :showCancelButton="true" :closeOnClickOverlay="true" :show="showSignatureUserUnit" title="签字板">
				<view class="slot-content">
					<view style="width: 750rpx ;height: 750rpx;">
						<l-signature disableScroll ref="signatureRef" :penColor="penColor" :penSize="penSize" :openSmooth="openSmooth"></l-signature>
					</view>
				</view>
			</u-modal>
		</view>
		<view>
			<u-modal @confirm="addOps(4)" @cancel="showSignatureUserMaintenance = !showSignatureUserMaintenance" :showCancelButton="true" :closeOnClickOverlay="true" :show="showSignatureUserMaintenance" title="签字板">
				<view class="slot-content">
					<view style="width: 750rpx ;height: 750rpx;">
						<l-signature disableScroll ref="signatureRef" :penColor="penColor" :penSize="penSize" :openSmooth="openSmooth"></l-signature>
					</view>
				</view>
			</u-modal>
		</view>
		<view>
			<u-modal @confirm="addOps(5)" @cancel="showSignatureUserCompoundMaintenance = !showSignatureUserCompoundMaintenance" :showCancelButton="true" :closeOnClickOverlay="true" :show="showSignatureUserCompoundMaintenance" title="签字板">
				<view class="slot-content">
					<view style="width: 750rpx ;height: 750rpx;">
						<l-signature disableScroll ref="signatureRef" :penColor="penColor" :penSize="penSize" :openSmooth="openSmooth"></l-signature>
					</view>
				</view>
			</u-modal>
		</view>
		<view>
			<u-modal @confirm="onSetFineNmae" @cancel="showFileNmae = !showFileNmae" :showCancelButton="true" :closeOnClickOverlay="true" :show="showFileNmae" title="填写姓名">
				<up-input placeholder="请填写姓名" border="surround" v-model="newUserName"></up-input>
			</u-modal>
		</view>
		<view>
			<u-datetime-picker title="选择时间" @confirm="onPeratingTimeStart" @cancel="showoPeratingTimeStart = !showoPeratingTimeStart" :show="showoPeratingTimeStart" v-model="preset.operatingTimeStart" mode="time"></u-datetime-picker>
		</view>
		<view>
			<u-datetime-picker title="选择时间" @confirm="onPeratingTimeEnd" @cancel="showPeratingTimeEndSon = !showPeratingTimeEndSon" :show="showPeratingTimeEndSon" v-model="preset.operatingTimeEnd" mode="time"></u-datetime-picker>
		</view>
		<view>
			<up-action-sheet @select="onGetFileMan" :actions="listUser" @close="showUser = !showUser" :closeOnClickOverlay="true" :closeOnClickAction="true" title="选择用户" :show="showUser"></up-action-sheet>
		</view>
		<qianziyu-select :show="showUserAdd" :title="title" type="radio" name="title" :dataLists="userList" @search="selectSearch" @cancel="showUserAdd = false" @submit="onUserAdd"></qianziyu-select>
	</view>
</template>

<script>
	import unitProfile from './unitProfileComponents.vue'
	import hearder from '../../components/header/header.vue'
	import catSignature from '../../components/catSignature/catSignature.vue';
	import canves1 from '../../components/canves1/canves1.vue';
	import http from "@/common/api/index.js";
	import { BASE_API, BASE_IP } from '@/common/http/url.js'
	// #ifdef APP-PLUS
	import { Signature } from 'vant';
	const filePicker = uni.requireNativePlugin('Ba-FilePicker')
	const signatures = uni.requireNativePlugin('Shawn-ModuleSign-SignatureModule')
	// #endif
	// #ifdef MP-WEIXIN
	const filePicker = ''
	const signatures = ''
	// #endif
	export default {
		components: {
			unitProfile,
			hearder,
			catSignature,
			canves1
		},
		data() {
			return {
				sex: [{ "text": "甲乙类厂房", "value": "甲乙类厂房" }, { "text": "丙类厂房", "value": "丙类厂房" }, { "text": "丁戊类厂房", "value": "丁戊类厂房" }, { "text": "甲乙类仓库", "value": "甲乙类仓库" }, { "text": "丙类仓库", "value": "丙类仓库" }, { "text": "丁戊类仓库", "value": "丁戊类仓库" }, { "text": "办公", "value": "办公" }, { "text": "普通商业", "value": "普通商业" }, { "text": "娱乐类商业", "value": "娱乐类商业" }, { "text": "体育场馆", "value": "体育场馆" }, { "text": "餐饮就业", "value": "餐饮就业" }, { "text": "酒店商业", "value": "酒店商业" }, { "text": "公寓商业", "value": "公寓商业" }],
				list1: [{ "name": "预申请" }, { "name": "单位信息" }, { "name": "人员信息" }, { "name": "邀请记录" }],
				list2: [{ "name": "安全管理人员" }, { "name": "消防操作人员" }, { "name": "动火操作人员" }],
				list2Current: 0,
				searNickname: '',
				preset: [],
				showFireman: false,
				api: BASE_IP,
				signaturesPath: "",
				filePath: "",
				user: null,
				type: 0,
				isSetFireList: true,
				isPresetUpdataOne: false,
				isPresetUpdataTow: false,
				isPresetUpdataThree: false,
				isPresetUpdataFour: false,
				isPresetUpdataFive: false,
				isfireControlAcceptanceDocument: false,
				ispointBitmap: false,
				showFireMaintenanceExpirationTime: false,
				fireMaintenanceExpirationTime: "",
				today: new Date().toISOString().slice(0, 10),
				showFireMaintenanceBeginTime: false,
				showSignatureFile: false,
				penColor: '#303133',
				penSize: 5,
				signatureUrl: '',
				openSmooth: true,
				uuid: "",
				showSignatureUserUnit: false,
				showSignatureUserMaintenance: false,
				showSignatureUserCompoundMaintenance: false,
				newUserName: "",
				showFileNmae: false,
				showoPeratingTimeStart: false,
				showPeratingTimeEndSon: false,
				presetSelectShowId: 0,
				showOpsAll: false,
				showOpsAllByUser: false,
				showOpsAllByUserdh: false,
				opsAllByUserItem: "",
				showUser: false,
				listUser: [],
				listInviter: [],
				listInviterAll: [],
				fireManList: [],
				allFireManList: [],
				tabsIndex: 0,
				userTabsIndex: 0,
				showUserAdd: false,
				userList: [],
				allUserList: [],
				username: '',
				actList1: [],
				actList: [{ "id": 2, "name": "上传证书" }, { "id": 3, "name": "上传签字" }, { "id": 4, "name": "清空证书", "color": "#fa3534" }, { "id": 5, "name": "清空签字", "color": "#fa3534" }, { "id": 6, "name": "移除此操作员", "color": "#fa3534" }],
				actListdh1: [],
				actListdh: [{ "id": 2, "name": "上传证书" }, { "id": 3, "name": "上传签字" }, { "id": 4, "name": "清空证书", "color": "#fa3534" }, { "id": 5, "name": "清空签字", "color": "#fa3534" }, { "id": 6, "name": "移除此操作员", "color": "#fa3534" }],
				list: { workName: '', address: '', type: '', name: '', mobile: '', area: '', aa: '', checked: '', id: '', userExpirationTime: "", unitDistrict: "", personInCharge: "", contactPersonInCharge: "" },
				workNameAction: false,
				filemans: [],
				filemansAll: [],
				user: null,
				title: null,
			};
		},
		onPullDownRefresh() {
			this.getPrall();
			uni.stopPullDownRefresh();
		},
		onLoad() {
			let user = uni.getStorageSync('user');
			if (user == null || user == '' || user.unitId == '') {
				const pages = getCurrentPages();
				const currentPage = pages[pages.length - 1];
				const url = currentPage.route;
				const options = currentPage.options;
				uni.setStorageSync('url', '/' + url);
				uni.redirectTo({ url: '/pagesMine/wxLogin/wxLogin' });
				return;
			}
			this.user = user;
			this.getPrall()
			this.getUsersByUnit()
			this.queryUnit()
			this.queryDevices();
			this.getUsersByInviter();
		},
		onShareAppMessage(res) {
			console.log('sm', res, this.user)
			let title = ""
			let path = ""
			if (this.userTabsIndex == 0) {
				title = this.user.nickName + '邀请您加入安全管理人员'
				path = '/pagesMine/wxLogin/wxLogin?power=3&inviter=' + this.user.uuid + '&groupId=' + res.target.id + '&unitId=' + this.user.unitId
			}
			if (this.userTabsIndex == 1) {
				title = this.user.nickName + '邀请您加入消防操作人员'
				path = '/pagesMine/wxLogin/wxLogin?power=3&inviter=' + this.user.uuid + '&groupId=' + res.target.id + '&unitId=' + this.user.unitId
			}
			if (this.userTabsIndex == 2) {
				title = this.user.nickName + '邀请您加入动火操作人员'
				path = '/pagesMine/wxLogin/wxLogin?power=3&inviter=' + this.user.uuid + '&groupId=' + res.target.id + '&unitId=' + this.user.unitId
			}
			return {
				debug: true,
				title: title,
				path: path,
				imageUrl: 'https://mp-bfea0f33-0deb-44c8-86f2-196dd6ca37a5.cdn.bspapp.com/test/head.jpg',
				success(res) {
					console.log('分享成功.', res);
				},
				fail(err) {
					console.log('分享失败', err);
				}
			}
		},
		methods: {
			openUserAdd() {
				this.showUserAdd = true;
				this.getUserList();
				this.title = '添加' + this.list2[this.userTabsIndex].name;
			},
			selectSearch(e) {
				console.log("selectSearch", e)
				if (e != '') {
					this.userList = this.allUserList.filter(res => {
						return res.title.indexOf(e) > -1
					})
				} else {
					this.userList = this.allUserList
				}
			},
			getUserList() {
				uni.showLoading();
				uni.request({
					header: {
						"Authorization": this.user.token
					},
					url: BASE_IP + "pc/unit/list/userList/" + this.userTabsIndex,
					method: "GET",
					success: (res) => {
						console.log('us', res.data);
						if (res.statusCode == 200) {
							this.userList = [];
							if (res.data && res.data.data) {
								let ul = [];
								for (let u in res.data.data) {
									ul.push(JSON.parse(res.data.data[u]));
								}
								this.userList = ul;
								this.allUserList = JSON.parse(JSON.stringify(ul));
							}
							uni.hideLoading()
						}
					},
					fail: () => {
						uni.hideLoading();
					}
				})
			},
			onUserAdd(item) {
				uni.showLoading();
				uni.request({
					header: {
						"Authorization": this.user.token,
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					url: BASE_IP + "pc/unit/list/userAdd",
					data: { uuid: item.uuid, type: this.userTabsIndex },
					method: "POST",
					success: (res) => {
						console.log('us', res.data);
						if (res.statusCode == 200) {
							this.showUserAdd = false;
							uni.showToast({ title: '添加成功', icon: 'success' });
							setTimeout(() => {
								console.log('sua', this.userTabsIndex);
								if (this.userTabsIndex == 0) {
									this.getPrall();
								} else {
									this.queryDevices();
								}
							}, 1000);
						}
						uni.hideLoading();
					},
					fail: () => {
						uni.hideLoading();
					}
				});
			},
			setStatus(item, status) {
				let _this = this;
				let data = { uuid: item.uuid, status: status };
				console.log('s1', item, status, data);
				uni.showModal({
					title: '提示',
					content: '确定要' + (status == 1 ? '同意' : '拒绝') + '吗',
					success: function(res) {
						if (res.confirm) {
							let url = BASE_IP + "pc/unit/list/inviterStatus"
							uni.request({
								header: {
									"Authorization": _this.user.token,
									'Content-Type': 'application/x-www-form-urlencoded'
								},
								url: url,
								data: data,
								method: "POST",
								success: (res) => {
									console.log('us', res.data);
									if (res.statusCode == 200) {
										uni.showToast({
											title: '操作成功',
											icon: 'success'
										})
										_this.getUsersByInviter();
									}
								}
							})
							uni.hideLoading()
						} else if (res.cancel) {

						}
					}
				});

			},
			submit() {
				uni.showToast({
					title: '需更换新接口！',
					icon: 'none'
				})
				return;
				let user = uni.getStorageSync('user')
				if (this.list.workName === "" || this.list.address === "" || this.list.type === "" || this.list.name === "" ||
					this.list.mobile === "" || this.list.aa === "" || this.list.checked === "") {
					uni.showToast({
						title: '需填写完整',
						icon: 'none',
						duration: 2000
					})

				} else if (this.list.id == '' || this.list.id == null) {
					// const store = useLoginStore()
					// console.log(this.list.checked)

					var Name = user.userName
					let mlist = {
						unitName: this.list.workName,
						unitAddress: this.list.address,
						unitAbbreviation: "",
						unitDistrict: this.list.unitDistrict,
						landPlanningType: this.list.type,
						safetyName: this.list.name,
						safetyPhone: this.list.mobile,
						unitType: this.list.checked,
						unitArea: this.list.aa,
						userName: Name,
						personInCharge: this.list.personInCharge,
						contactPersonInCharge: this.list.contactPersonInCharge
					}

					console.log(mlist)


					// console.log("传的数据：", mlist)
					let url = BASE_IP + "pc/unit/insert"
					let _this = this
					uni.request({
						url: url,
						header: {
							"Authorization": user.token
						},
						data: mlist,
						method: "POST",
						success: (res) => {
							if (res.statusCode == 200) {
								uni.showToast({
									title: "提交成功",
									icon: "success"
								})
								// _this.status = false
								this.queryUnit()
								return
							}
						},
						fail: () => {
							uni.showToast({
								title: "提交失败",
								icon: "error"
							})
							return
						}
					})

				} else if (this.list.id != null || this.list.id != '') {
					let ulist = {
						unitName: this.list.workName,
						unitAddress: this.list.address,
						unitAbbreviation: "",
						unitDistrict: this.list.unitDistrict,
						landPlanningType: this.list.type,
						safetyName: this.list.name,
						safetyPhone: this.list.mobile,
						unitType: this.list.checked,
						unitArea: this.list.aa,
						userName: Name,
						unitID: this.list.id,
						personInCharge: this.list.personInCharge,
						contactPersonInCharge: this.list.contactPersonInCharge
					}
					if (ulist.personInCharge === ulist.safetyName) {
						uni.showModal({
							title: "提示",
							content: "安全负责人和主要负责人不能为同一个人！",
							showCancel: false
						})
						return
					}
					console.log(ulist)
					let url = BASE_IP + "pc/unit/update"
					uni.request({
						url: url,
						header: {
							"Authorization": user.token
						},
						data: ulist,
						method: "POST",
						success: (res) => {
							if (res.statusCode == 200) {
								uni.showToast({
									title: "修改成功",
									icon: "success"
								})
								// _this.status = false

								this.queryUnit()

								return
							}
						},
						fail: () => {
							uni.showToast({
								title: "修改失败",
								icon: "error"
							})
							return
						}
					})
				}
				this.status = false
			},
			queryDevices() {
				let url = BASE_IP + "pc/hot/work/get/fileman"
				let user = uni.getStorageSync("user")
				uni.request({
					header: {
						"Authorization": user.token,
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					url: url,
					success: (res) => {
						console.log(res)
						if (res.statusCode == 200) {
							if (res.data.code == 0) {
								this.devices = []
								return
							}
							if (res.data.code == 1) {
								this.filemans = []
								this.filemans = res.data.data
								this.filemansAll = JSON.parse(JSON.stringify(res.data.data))
								console.log("动火操作工", this.filemans)
							}
						}
					}
				})
			},
			showWorkNameAction(res) {
				if (res.id == 1) {
					console.log("修改单位名称")
					let _this = this;
					uni.showModal({
						editable: true,
						placeholderText: "请输入单位名称",
						title: "修改单位名称",
						success: (res) => {
							if (res.cancel) {
								return
							}
							if (res.content) {
								let user = uni.getStorageSync("user")
								let url = BASE_IP + "pc/unit/updateUnit"
								let data = {
									unitId: _this.list.id,
									unitName: res.content
								};
								uni.request({
									url: url,
									header: {
										"Authorization": user.token,
										'Content-Type': 'application/x-www-form-urlencoded'
									},
									data: data,
									method: "POST",
									success: (res) => {
										if (res.statusCode == 200 && res.data != '') {
											_this.list.workName = data.unitName;
											uni.showToast({
												title: "保存成功",
												icon: 'success'
											})
										}
									},
									fail: () => {
										uni.showToast({
											title: "服务器出现问题",
											icon: "error"
										})
									}
								})
							} else {
								uni.showToast({
									icon: "error",
									title: "请输入单位名称"
								})
								return
							}
						}
					})
				}
			},
			queryUnit() {
				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/unit/query/" + user.userName
				uni.request({
					url: url,
					header: {
						"Authorization": user.token
					},
					success: (res) => {
						if (res.statusCode == 200 && res.data != '') {
							console.log("u.q.r", res.data)
							this.list.name = res.data.safetyName
							this.list.type = res.data.landPlanningType
							this.list.mobile = res.data.safetyPhone
							this.list.workName = res.data.unitName
							this.list.address = res.data.unitAddress
							this.list.aa = res.data.unitArea
							this.list.id = res.data.unitID
							this.list.checked = res.data.unitType
							this.list.userExpirationTime = user.userExpirationTime
							this.list.unitDistrict = res.data.unitDistrict
							this.list.personInCharge = res.data.personInCharge
							this.list.contactPersonInCharge = res.data.contactPersonInCharge
							this.status = false
							let title = res.data.unitDistrict + "消防重点单位智能管理系统"
							uni.setStorageSync("unit", this.list)
						}

						// console.log("获取单位对象：",res)
					},
					fail: () => {
						uni.showToast({
							title: "服务器出现问题",
							icon: "error"
						})
					}
				})
			},
			tabClick(item) {
				console.log('item', item);
				this.tabsIndex = item.index
			},
			tab2Click(index) {
				console.log('index', index);
				this.userTabsIndex = index
			},
			searchFun(e) {
				console.log(111, e)
				if (this.userTabsIndex == 0) {
					if (e != '') {
						this.fireManList = this.allFireManList.filter(res => {
							return res.nickname.indexOf(e) > -1
						})
					} else {
						this.fireManList = this.allFireManList
					}
					console.log(this.fireManList)
				} else {
					if (e != '') {
						this.filemans = this.filemansAll.filter(res => {
							return res.nickName.indexOf(e) > -1
						})
					} else {
						this.filemans = this.filemansAll
					}
				}
			},
			searchFunInviter(e) {
				console.log('searchFunInviter', e)
				if (e != '') {
					this.listInviter = this.listInviterAll.filter(res => {
						return res.nickname.indexOf(e) > -1
					})
				} else {
					this.listInviter = this.listInviterAll
				}
			},
			toTest() {
				uni.navigateTo({
					url: "/pages/test/test"
				})
			},
			/**
			 * 获取本单位所属的用户
			 */
			getUsersByUnit() {
				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/unit/list/man/" + user.unitId
				uni.request({
					header: {
						"Authorization": user.token
					},
					url: url,
					method: "POST",
					success: (res) => {
						// console.log(res)
						if (res.statusCode == 200) {
							// console.log("获取单位所属的用户：", res)
							if (res.data.code == 1) {
								let temp_list = []
								for (let index in res.data.data) {
									let item = JSON.parse(res.data.data[index])
									let user_item = {
										name: "用户名：" + item.name,
										account: item.account,
										subname: "账号：" + item.account
									}
									temp_list.push(user_item)
								}
								this.listUser = temp_list
							}
						}
						if (res.statusCode == 500) {
							// uni.showToast({
							// 	title: "添加失败",
							// 	icon: "error"
							// })
						}
					}
				})
				uni.hideLoading()
			},
			getUsersByInviter() {
				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/unit/list/inviter/" + user.uuid
				uni.request({
					header: {
						"Authorization": user.token
					},
					url: url,
					method: "POST",
					success: (res) => {
						console.log('ui', res.data);
						if (res.statusCode == 200) {
							if (res.data.code == 1) {
								let temp_list = []
								for (let index in res.data.data) {
									let item = JSON.parse(res.data.data[index])
									item.userCreateTime = item.userCreateTime.replace("T", " ");
									temp_list.push(item)
								}
								this.listInviter = temp_list
								this.listInviterAll = temp_list
							}
						}
					}
				})
				uni.hideLoading()
			},
			onGetFileMan(res) {
				console.log(res)
				this.addFileMan(res.account)
			},
			userSelectClick(res) {
				let item = this.opsAllByUserItem
				console.log(res)
				if (res.id == 1) {
					uni.showModal({
						editable: true,
						title: "请输入用户名",
						success: (res) => {
							if (res.confirm) {
								console.log(res.content)
								if (res.content) {
									this.newUserName = res.content
									this.onSetFineNmae()
								} else {
									uni.showToast({
										icon: "error",
										title: "用户名为空"
									})
									return
								}
							}
						}
					})
				}
				if (res.id == 2) {
					this.onLoadCertificatFile(item.uuid)
				}
				if (res.id == 3) {
					this.onSignaturesFile(item.uuid)
				}
				if (res.id == 4) {
					let url = BASE_IP + "pc/user/del/certificate/" + item.uuid
					let _this = this
					uni.request({
						method: "DELETE",
						header: { "Authorization": this.user.token },
						url: url,
						success: (res) => {
							if (res.statusCode == 200) {
								uni.showToast({
									icon: "success",
									title: "更新成功"
								})
								this.getPrall()
							} else {
								uni.showToast({
									icon: "error",
									title: "更新失败"
								})
							}
						}
					})
				}
				if (res.id == 5) {
					let url = BASE_IP + "pc/user/del/signatures/" + item.uuid
					let _this = this
					uni.request({
						method: "DELETE",
						header: {
							"Authorization": this.user.token
						},
						url: url,
						success: (res) => {
							if (res.statusCode == 200) {
								uni.showToast({
									icon: "success",
									title: "更新成功"
								})
								this.getPrall()
							} else {
								uni.showToast({
									icon: "error",
									title: "更新失败"
								})
							}
						}
					})
				}
				if (res.id == 6) {
					uni.showModal({
						title: "提示",
						content: "您确定移除此操作员吗？",
						success: (res) => {
							if (res.confirm) {
								let url = BASE_IP + "pc/fireman/del/deletefireman/" + item.name
								let _this = this
								uni.request({
									method: "DELETE",
									header: {
										"Authorization": this.user.token
									},
									url: url,
									success: (res) => {
										if (res.statusCode == 200) {
											uni.showToast({
												icon: "success",
												title: "更新成功"
											})
											this.getPrall()
										} else {
											uni.showToast({
												icon: "error",
												title: "更新失败"
											})
										}
									}
								})
							}
						}
					})
				}
				if (res.id == 7 || res.id == 8) {
					let id = this.type == 0 ? item.id : item.id;
					let nickname = this.type == 0 ? item.nickname : item.nickName;
					let title = "您确定设置【" + nickname + "】为组长吗？";
					if (item.team == 1) {
						title = "您确定取消【" + nickname + "】的组长身份吗？";
					}
					let _this = this
					uni.showModal({
						title: "提示",
						content: title,
						success: (res) => {
							if (res.confirm) {
								let url = BASE_IP + "pc/unit/list/userTeam"
								uni.request({
									method: "POST",
									header: {
										"Authorization": _this.user.token,
										'Content-Type': 'application/x-www-form-urlencoded'
									},
									data: { type: _this.type, id: id },
									url: url,
									success: (res) => {
										if (res.statusCode == 200) {
											uni.showToast({
												icon: "success",
												title: "更新成功"
											})
											if (_this.type == 0) {
												_this.getPrall()
											} else {
												_this.queryDevices();
											}
										} else {
											uni.showToast({
												icon: "error",
												title: "更新失败"
											})
										}
									}
								})
							}
						}
					})
				}
			},
			onShowOpsAllByUser(res) {
				this.type = 0;
				this.showOpsAllByUser = true
				this.opsAllByUserItem = res
				console.log('onShowOpsAllByUser', res);
				this.actList1 = JSON.parse(JSON.stringify(this.actList));
				if (res.team == 1) {
					//this.actList1.unshift({ id: 8, name: '取消组长' });
				} else {
					//this.actList1.unshift({ id: 7, name: '置为组长' });
				}
				console.log('ss1', this.actList, this.actList1)
			},
			onShowOpsAllByUserdh(res) {
				this.type = 1;
				this.showOpsAllByUserdh = true
				this.opsAllByUserItem = res
				console.log('type-1', res);
				this.actListdh1 = JSON.parse(JSON.stringify(this.actListdh));
				if (res.team == 1) {
					//this.actListdh1.unshift({ id: 8, name: '取消组长' });
				} else {
					//this.actListdh1.unshift({ id: 7, name: '置为组长' });
				}
				console.log('ss2', this.actListdh, this.actListdh1)
			},
			presetSelectClick(res) {
				console.log(res.id)
				let id = this.presetSelectShowId
				console.log(id)

				if (id == 1) { //单位消防专用印章
					if (res.id == 1) {
						this.addOps(1)
					}
					if (res.id == 2) {

						let url = BASE_IP + "pc/presetfunction/delpreinstaimg/" + this.user.unitId + "/1"
						console.log(url)
						this.delpreinstaImg(url)
					}
				}
				if (id == 2) { //消防维保合同
					if (res.id == 1) {
						this.addOps(2)
					}
					if (res.id == 2) {
						let url = BASE_IP + "pc/presetfunction/delpreinstaimg/" + this.user.unitId + "/2"
						this.delpreinstaImg(url)
					}
				}
				if (id == 3) { //用户单位签字
					if (res.id == 1) {
						this.showSignatureUserUnit = !this.showSignatureUserUnit
					}
					if (res.id == 2) {
						let url = BASE_IP + "pc/presetfunction/delpreinstaimg/" + this.user.unitId + "/3"
						this.delpreinstaImg(url)
					}
				}
				if (id == 4) { //维保单位签字
					if (res.id == 1) {
						this.showSignatureUserMaintenance = !this.showSignatureUserMaintenance
					}
					if (res.id == 2) {
						let url = BASE_IP + "pc/presetfunction/delpreinstaimg/" + this.user.unitId + "/4"
						this.delpreinstaImg(url)
					}
				}
				if (id == 5) { //维保复合单位签字
					if (res.id == 1) {
						this.showSignatureUserCompoundMaintenance = !this.showSignatureUserCompoundMaintenance
					}
					if (res.id == 2) {
						let url = BASE_IP + "pc/presetfunction/delpreinstaimg/" + this.user.unitId + "/5"
						this.delpreinstaImg(url)
					}
				}
				if (id == 6) { //点位图
					if (res.id == 1) {
						this.addOps(8)
					}
					if (res.id == 2) {
						let url = BASE_IP + "pc/presetfunction/delpreinstaimg/" + this.user.unitId + "/6"
						this.delpreinstaImg(url)
					}
				}
				if (id == 7) { //消防验收文件
					if (res.id == 1) {
						this.addOps(7)
					}
					if (res.id == 2) {
						let url = BASE_IP + "pc/presetfunction/delpreinstaimg/" + this.user.unitId + "/7"
						this.delpreinstaImg(url)
					}
				}
				if (id == 8) {
					if (res.id == 1) {
						this.addOps(9)
					}
					if (res.id == 2) {
						let url = BASE_IP + "pc/user/face/del"
						this.delpreinstaImg(url)
					}
				}
				if (id == 9) {
					console.log("id===========9")
					if (res.id == 1) {
						this.addOps(10)
					}
					if (res.id == 2) {
						let url = BASE_IP + "pc/user/idInfo/del"
						this.delpreinstaImg(url)
					}
				}
				if (id == 10) {
					console.log("id===========10")
					if (res.id == 1) {
						this.addOps(11)
					}

					if (res.id == 2) {
						let url = BASE_IP + "pc/user/operationcertificate/del"
						this.delpreinstaImg(url)
					}
				}

			},
			delpreinstaImg(url) {
				let _this = this
				uni.request({
					method: "DELETE",
					header: {
						"Authorization": this.user.token
					},
					url: url,
					success: (res) => {
						// console.log(res)
						if (res.statusCode == 200) {
							uni.showToast({
								icon: "success",
								title: "操作成功"
							})
							_this.getPrall()

						} else {
							uni.showToast({
								icon: "error",
								title: "操作失败"
							})
						}
					}
				})
			},
			presetSelectShow(res) {
				this.presetSelectShowId = res
				this.showOpsAll = !this.showOpsAll
				console.log(111, this.showOpsAll)
			},
			onPeratingTimeEnd(r) {
				// console.log(r)
				// if (this.user.power == 3) {
				// 	uni.showToast({
				// 		title: "权限不足",
				// 		icon: "error"
				// 	})
				// 	return
				// }

				if (r.value == "") {
					uni.showToast({
						title: "请选择时间",
						icon: "error"
					})
					return
				}

				let url = BASE_IP + "pc/presetfunction/operatingtimeend/" + this.preset.unitId + "/" + r.value
				let _this = this
				uni.request({
					header: {
						"Authorization": this.user.token
					},
					url: url,
					success: (res) => {
						// console.log(res)
						if (res.statusCode == 200) {
							let time = setTimeout((res) => {
								_this.getPrall()
							}, 500)

							let time1 = setTimeout((res) => {
								_this.getPrall()
							}, 800)
						}
					}
				})
				this.showPeratingTimeEndSon = !this.showPeratingTimeEndSon
			},
			onPeratingTimeStart(r) {
				// if (this.user.power == 3) {
				// 	uni.showToast({
				// 		title: "权限不足",
				// 		icon: "error"
				// 	})
				// 	return
				// }
				if (r.value == "") {
					uni.showToast({
						title: "请选择时间",
						icon: "error"
					})
					return
				}

				let url = BASE_IP + "pc/presetfunction/operatingtimestart/" + this.preset.unitId + "/" + r.value
				let _this = this
				uni.request({
					header: {
						"Authorization": this.user.token
					},
					url: url,
					success: (res) => {
						// console.log(res)
						if (res.statusCode == 200) {
							let time = setTimeout((res) => {
								_this.getPrall()
							}, 500)

							let time1 = setTimeout((res) => {
								_this.getPrall()
							}, 800)
						}
					}
				})
				this.showoPeratingTimeStart = !this.showoPeratingTimeStart
			},
			onShowFileNmae(id) {
				this.uuid = id
				this.showFileNmae = true
			},
			onSetFineNmae() {
				let id = this.opsAllByUserItem.name
				console.log(this.opsAllByUserItem)
				if (this.newUserName == "") {
					uni.showToast({
						title: "名字未输入",
						icon: "error"
					})
					// @PostMapping("/pc/user/update/userName/{userName}/{name}")
					return
				}

				let url = BASE_IP + "pc/user/update/nickName/" + id + "/" + this.newUserName
				console.log("获取链接：", url)
				let _this = this
				uni.request({
					header: {
						"Authorization": this.user.token
					},
					url: url,
					method: "POST",
					success: (res) => {
						console.log(res)
						if (res.statusCode == 200) {
							_this.user.nickName = _this.newUserName
							uni.setStorageSync("user", _this.user)
							uni.showToast({
								title: "添加成功",
								icon: "success"
							})
							let time = setTimeout((res) => {
								_this.getPrall()
							}, 500)

							let time1 = setTimeout((res) => {
								_this.getPrall()
							}, 800)
						}
						if (res.statusCode == 404) {
							uni.showToast({
								title: "失败",
								icon: "error"
							})
							return
						}
						if (res.statusCode == 500) {
							uni.showToast({
								title: "失败",
								icon: "error"
							})
							return
						}
					}
				})
				this.showFileNmae = false

			},
			getTest() {

			},
			onSignature() {
				console.log(11111)
				this.$refs.signatureRef.canvasToTempFilePath({
					success: (res) => {
						// 是否为空画板 无签名
						console.log(res.isEmpty)
						console.log(res)
						// 生成图片的临时路径
						// H5 生成的是base64
						this.signatureUrl = res.tempFilePath
						console.log("签字图片：", this.signatureUrl)
					}
				})

				this.showSignature = false
			},
			addFileMan(username) {
				// let muns = ""
				console.log("获取输入的用户：", username)
				let user = uni.getStorageSync("user")
				let fireManList = this.preset.fireManList
				if (!username) {
					uni.showToast({
						title: "账号为空",
						icon: "error"
					})
					return
				}
				for (let i in fireManList) {
					if (fireManList[i].name == username) {
						uni.showToast({
							title: "此操作员已存在",
							icon: "error"
						})
						return
					}
				}
				// muns = username
				let url = BASE_IP + "pc/fireman/insert/fireman/" + username + "/" + user.unitId
				uni.request({
					header: {
						"Authorization": user.token
					},
					url: url,
					method: "POST",
					success: (res) => {
						console.log(res)
						if (res.statusCode == 200) {
							// console.log("插入成功")
							if (res.data.code == 0) {
								uni.showModal({
									title: "提示",
									content: res.data.msg,
									showCancel: false
								})
								return
							}
							uni.showToast({
								title: "添加成功",
								icon: "success"
							})
							this.getPrall()
						}
						if (res.statusCode == 500) {
							uni.showToast({
								title: "添加失败",
								icon: "error"
							})
						}
					}
				})
			},
			onLoadCertificat(id) {
				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/fire/upload/certificate/" + id + "/" + user.unitId
				uni.chooseImage({
					count: 1,
					sizeType: ['original', 'compressed'],
					sourceType: ['camera', 'album'],
					success: (res) => {
						// console.log(res);
						const tempFilePaths = res.tempFilePaths[0];
						this.upload(url, tempFilePaths)
					}
				});
			},
			onLoadCertificatFile(id) {
				let url = BASE_IP + "pc/user/upload/certificate/" + id
				uni.chooseImage({
					count: 5,
					sizeType: ['original', 'compressed'],
					sourceType: ['camera', 'album'],
					success: (res) => {
						// console.log(res);
						// const tempFilePaths = res.tempFilePaths[0];
						// this.upload(url, tempFilePaths)
						res.tempFilePaths.forEach(itme1 => {
							this.upload(url, itme1)
						})
					}
				});

			},
			selctFile() {
				filePicker.selectFile({ //自定义类型分组
						selectType: 2,
						maxCount: 9,
					},
					(res) => {
						if (res.data) {
							const maxSizeInBytes = 10 * 1024 * 1024
							this.filePath = res.data[0].absolutePath
							if (res.data[0].size > maxSizeInBytes) {
								uni.showToast({
									title: "文件过长",
									icon: "error"
								})
								return
							}
						}
					});
			},
			getPrall() {
				//获取预设功能对象数据
				uni.showLoading({ title: '加载中' });
				let user = uni.getStorageSync("user")
				this.user = user
				let url = this.api + "pc/presetfunction/find/presetFunction/" + user.unitId + "/" + user.uuid
				uni.request({
					header: {
						"Authorization": user.token,
					},
					url: url,
					success: (res) => {
						if (res.statusCode == 200) {
							let pralldata = res.data
							this.preset = pralldata
							if (pralldata.fireManList != null && pralldata.fireManList != undefined && pralldata.fireManList != "") {
								for (let i in pralldata.fireManList) {
									if (pralldata.fireManList[i].name == user.userName) {
										user.signature = pralldata.fireManList[i].signature
										uni.setStorageSync("user", user)
										uni.hideLoading()
										return
									}
								}
							}
							console.log('eee', pralldata);
							this.fireManList = pralldata.fireManVOList
							this.allFireManList = JSON.parse(JSON.stringify(this.fireManList))
							console.log("操作工人数据", this.fireManList)
							console.log("========>", pralldata)
						} else {
							uni.showToast({
								icon: "error",
								title: "请求失败"
							})
						}
					},
					fail: (res) => {
						// console.log("请求失败：", res)
						uni.showToast({
							icon: "error",
							title: "请求失败"
						})
					}
				})
				uni.hideLoading()
			},
			setName(res) {
				let user = uni.getStorageSync("user")
				let vaule = res.detail.value
				let id = res.target.id
				if (vaule != "") {
					let url = BASE_IP + "pc/fire/update/name/" + id + "/" + vaule
					uni.request({
						header: {
							"Authorization": user.token,
						},
						url: url,
						method: "POST",
						success: (res) => {
							if (res.statusCode == 200) {
								this.getPrall()
							}
						},
						fail: () => {
							uni.showToast({
								title: "添加名字失败",
								icon: "error"
							})
							return
						}
					})
				}

			},
			onSignatures(id) {
				this.uuid = id
				this.showSignatureFile = true
			},
			onSignaturesFile(id) {
				this.uuid = id
				this.showSignatureFile = true
			},
			onSignaturesFileSon() {
				let uuid = this.uuid
				this.$refs.signatureRefNew.canvasToTempFilePath({
					success: (res) => {
						// 是否为空画板 无签名
						console.log(res.isEmpty)
						if (res.isEmpty) {
							return
						}
						// console.log(res)
						// 生成图片的临时路径
						// H5 生成的是base64
						// this.signatureUrl = res.tempFilePath
						// console.log("签字图片：",this.signatureUrl)
						let user = uni.getStorageSync("user")
						let url = BASE_IP + "pc/user/upload/signature/" + uuid
						this.upload(url, res.tempFilePath)
						this.showSignatureFile = false
					}
				})

			},
			/**
			 * @param {Object} url 上传文件的服务器地址
			 * @param {Object} files 本地文件的路径数组
			 */
			uploads(url, filePath) {
				console.log("====>", url, filePath)
				let user = uni.getStorageSync("user")
				uni.uploadFile({
					header: {
						"Authorization": user.token,
					},
					name: "file",
					url: url,
					files: filePath,
					success: (res) => {
						console.log(res)
						if (res.statusCode == 500) {
							uni.showToast({
								icon: "error",
								title: "上传失败"
							})
							return
						}
						if (res.statusCode == 404) {
							console.log(res)
							uni.showToast({
								icon: "error",
								title: "上传失败"
							})
							return
						}
						if (res.statusCode == 200) {
							uni.showToast({
								title: "上传成功",
								icon: "success"
							})
							this.searNickname = null
							this.getPrall()
						}
					},
					fail: (res) => {
						uni.showToast({
							title: "上传失败,请重试",
							icon: "error"
						})
					}
				})
				let time = setTimeout((res) => {
					this.getPrall()
				}, 500)
			},
			/**
			 * @param {Object} url 上传文件的服务器地址
			 * @param {Object} filePath 本地文件的路径
			 */
			uploadNew(url, filePath) {
				console.log("====>", url, filePath)
				let user = uni.getStorageSync("user")
				uni.uploadFile({
					header: {
						"Authorization": user.token,
					},
					name: "file",
					url: url,
					filePath: filePath,
					success: (res) => {
						console.log(res)
						if (res.statusCode == 500) {
							uni.showToast({
								icon: "error",
								title: "上传失败"
							})
							return
						}
						if (res.statusCode == 404) {
							console.log(res)
							uni.showToast({
								icon: "error",
								title: "上传失败"
							})
							return
						}
						if (res.statusCode == 200) {
							let data = JSON.parse(res.data)
							console.log(data)
							if (data.code != 0) {
								uni.showModal({
									title: "提示",
									content: data.data,
									showCancel: false
								})
								this.getPrall()
								return
							} else {
								uni.showModal({
									title: "提示",
									content: data.msg,
									showCancel: false
								})
								return
							}

							// uni.showToast({
							// 	title: "上传成功",
							// 	icon: "success"
							// })
							// this.getPrall()
						}
					},
					fail: (res) => {
						uni.showToast({
							title: "上传失败,请重试",
							icon: "error"
						})
					}
				})
				let time = setTimeout((res) => {
					this.getPrall()
				}, 500)
			},
			/**
			 * @param {Object} url 上传文件的服务器地址
			 * @param {Object} filePath 本地文件的路径
			 */
			upload(url, filePath) {
				console.log("upload", url, filePath)
				let user = uni.getStorageSync("user")
				uni.uploadFile({
					header: {
						"Authorization": user.token,
					},
					name: "file",
					url: url,
					filePath: filePath,
					success: (res) => {
						console.log(res)
						if (res.statusCode == 500) {
							uni.showToast({
								icon: "error",
								title: "上传失败"
							})
							return
						}
						if (res.statusCode == 404) {
							console.log(res)
							uni.showToast({
								icon: "error",
								title: "上传失败"
							})
							return
						}
						if (res.statusCode == 200) {
							uni.showToast({
								title: "上传成功",
								icon: "success"
							})
							this.getPrall()
						}
					},
					fail: (res) => {
						uni.showToast({
							title: "上传失败,请重试",
							icon: "error"
						})
					}
				})
				setTimeout(() => {
					this.getPrall()
				}, 500)
			},
			onPreview(url) {
				console.log(11111, url)
				const regex = /\.(pdf)$/i;
				const regexv = /\.(jpg|png|jpeg)$/i;
				const matchPdf = regex.test(url);
				const matchPdfv = regexv.test(url);
				if (matchPdf) {

					let urls = BASE_IP + url
					// console.log(urls)
					let filelist = {
						name: '预览',
						fileSrc: urls,
						isFileDown: true
					}
					uni.navigateTo({
						url: "/pages/common/fileView",
						success: (res) => {
							// 通过eventChannel向被打开页面传送数据
							res.eventChannel.emit("dataFun", {
								data: filelist,
							});
						},
					});
				} else if (matchPdfv) {
					uni.showLoading({
						title: "正在加载"
					})
					let urls = BASE_IP + url
					console.log(urls)
					let arr = []
					arr.push(urls)
					uni.previewImage({
						urls: arr,
						current: arr.length,
						success(r) {
							uni.hideLoading();
							console.log(r)
						},
						fail() {
							uni.hideLoading();
							uni.showToast({
								title: "加载失败",
								icon: "error"
							})
						}
					})
				}
			},
			onPreviewImgs(res) {
				let temp = JSON.parse(res)
				let imgs = []
				for (let i in temp) {
					let urls = BASE_API + temp[i]
					imgs.push(urls)
				}
				console.log("查看的数据：", temp, imgs)

				uni.previewImage({
					urls: imgs,
					current: imgs.length,
					success(r) {
						uni.hideLoading();
					},
					fail() {
						uni.hideLoading();
						uni.showToast({
							title: "加载失败",
							icon: "error"
						})
					}
				})

				// uni.navigateTo({
				// 	url: '/pages/showimg/showimg?imgs=' + JSON.stringify(imgs) + '&current=1',
				// 	animationType: "fade-in",
				// })
			},
			addOps(id) {
				let user = uni.getStorageSync("user")
				// if (user.power == 3) {
				// 	uni.showToast({
				// 		title: "权限不足",
				// 		icon: "error"
				// 	})
				// 	return
				// }
				if (id < 6) {
					if (id == 1) {
						uni.showModal({
							editable: true,
							placeholderText: "请输入公司名称",
							title: "消防专用章生成",
							success: (res) => {
								if (res.cancel) {
									return
								}
								if (res.confirm) {
									let user = uni.getStorageSync("user")
									let name = res.content
									if (name != "") {
										let url = BASE_IP + "pc/iotFireAlarmRecord/insertOrUpdate/seal/" +
											name + "/" + user.unitId
										let _this = this

										uni.request({
											url: url,
											header: {
												"Authorization": user.token,
											},
											method: "POST",
											success: (r) => {
												console.log(r)
												let imgUrl = BASE_IP + r.data.path
												console.log(imgUrl)
												if (r.statusCode == 200) {
													uni.showToast({
														icon: "success",
														title: "生成成功"
													})
													this.getPrall()

													return
												} else {
													uni.showToast({
														icon: "success",
														title: "生成失败"
													})
												}
											}
										})
									} else {
										uni.showToast({
											title: "请输入名称",
											icon: "error"
										})
										return
									}
								}
							}
						})

						// uni.chooseImage({
						// 	count: 1,
						// 	sizeType: ['original', 'compressed'],
						// 	sourceType: ['camera', 'album'],
						// 	success: (res) => {
						// 		// console.log(res);
						// 		const tempFilePaths = res.tempFilePaths[0];
						// 		let url = BASE_IP + "pc/presetfunction/upload/unitFireSeal/" + user.unitId
						// 		this.upload(url, tempFilePaths)
						// 	}
						// });

					} else if (id == 2) {
						let url = BASE_IP + "pc/presetfunction/upload/fireContract/" + user.unitId
						uni.chooseImage({
							count: 5,
							sizeType: ['original', 'compressed'],
							sourceType: ['camera', 'album'],
							success: (res) => {
								res.tempFilePaths.forEach(itme1 => {
									this.upload(url, itme1)
								})
							}
						});

					} else if (id == 3) {
						let url = BASE_IP + "pc/presetfunction/upload/fireUserUnit/" + user.unitId
						this.$refs.signatureRef.canvasToTempFilePath({
							success: (res) => {
								if (res.isEmpty) {
									return
								}
								this.upload(url, res.tempFilePath)
							}
						})
						this.showSignatureUserUnit = false

					} else if (id == 4) {
						let url = BASE_IP + "pc/presetfunction/upload/fireMaintenanceUnit/" + user.unitId
						this.$refs.signatureRef.canvasToTempFilePath({
							success: (res) => {
								if (res.isEmpty) {
									return
								}
								this.upload(url, res.tempFilePath)
							}
						})
						this.showSignatureUserMaintenance = false
					} else if (id == 5) {
						let url = BASE_IP + "pc/presetfunction/upload/fireMaintenanceReviewUnit/" + user
							.unitId
						this.$refs.signatureRef.canvasToTempFilePath({
							success: (res) => {
								if (res.isEmpty) {
									return
								}
								this.upload(url, res.tempFilePath)
							}
						})
						this.showSignatureUserCompoundMaintenance = false
					}
					this.getPrall()
				} else if (id == 6) {

				} else if (id == 7) {
					let url = BASE_IP + "pc/presetfunction/upload/fireControlAcceptanceDocument/" + user.unitId
					uni.chooseImage({
						count: 5,
						sizeType: ['original', 'compressed'],
						sourceType: ['camera', 'album'],
						success: (res) => {
							res.tempFilePaths.forEach(itme1 => {
								this.upload(url, itme1)
							})

						}
					});
				} else if (id == 8) {
					let url = BASE_IP + "pc/presetfunction/upload/pointBitmap/" + user.unitId
					uni.chooseImage({
						count: 5,
						sizeType: ['original', 'compressed'],
						sourceType: ['camera', 'album'],
						success: (res) => {
							// console.log(res);
							const tempFilePaths = res.tempFilePaths[0];
							console.log(res)
							// this.upload(url, tempFilePaths)
							let _this = this
							res.tempFilePaths.forEach((itme) => {
								console.log(itme.path)
								setTimeout(() => {
									_this.upload(url, itme)
								}, 1500)
							})
						}
					});
				} else if (id == 9) {
					let url = BASE_IP + "pc/user/upload/face"
					uni.chooseImage({
						count: 1,
						sizeType: ['original', 'compressed'],
						sourceType: ['camera', 'album'],
						success: (res) => {
							console.log(res);

							const tempFilePaths = res.tempFilePaths[0];
							// console.log(res)
							// this.upload(url, tempFilePaths)
							let _this = this
							// let img_path = res.tempFilePaths[]
							// res.tempFilePaths.forEach((itme) => {
							// 	console.log(itme.path)
							// 	setTimeout(() => {
							_this.uploadNew(url, tempFilePaths)
							// 	}, 1500)
							// })
						}
					});
				} else if (id == 10) {
					let url = BASE_IP + "pc/user/upload/idinfo"
					uni.chooseImage({
						count: 1,
						sizeType: ['original', 'compressed'],
						sourceType: ['camera', 'album'],
						success: (res) => {
							console.log(res);

							const tempFilePaths = res.tempFilePaths[0];
							// console.log(res)
							// this.upload(url, tempFilePaths)
							let _this = this
							// let img_path = res.tempFilePaths[]
							// res.tempFilePaths.forEach((itme) => {
							// 	console.log(itme.path)
							// 	setTimeout(() => {
							_this.uploadNew(url, tempFilePaths)
							// 	}, 1500)
							// })
						}
					});
				} else if (id == 11) {
					let url = BASE_IP + "pc/user/upload/operationcertificate"
					uni.chooseImage({
						count: 1,
						sizeType: ['original', 'compressed'],
						sourceType: ['camera', 'album'],
						success: (res) => {
							console.log(res);

							const tempFilePaths = res.tempFilePaths[0];
							// console.log(res)
							// this.upload(url, tempFilePaths)
							let _this = this
							// let img_path = res.tempFilePaths[]
							// res.tempFilePaths.forEach((itme) => {
							// 	console.log(itme.path)
							// 	setTimeout(() => {
							_this.uploadNew(url, tempFilePaths)
							// 	}, 1500)
							// })
						}
					});
				}
			},
			setSeal(res) {
				// console.log(res)
				let vaule = res.detail.value
				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/presetfunction/upload/fireURL/" + user.unitId + "/" + vaule
				uni.request({
					header: {
						"Authorization": user.token,
					},
					url: url,
					method: "POST"
				})
				this.getPrall()
			},
			toViewOps(res) {
				this.onPreview(res)
			},
			onSetFireList(item) {
				if (this.isSetFireList) {
					this.isSetFireList = false
				} else {
					// console.log("完成：", item)
					this.isSetFireList = true
					let time = setTimeout((res) => {
						this.getPrall()
					}, 500)
					let time1 = setTimeout((res) => {
						this.getPrall()
					}, 800)
				}
			},
			onSelectData() {

			},
			onFireMaintenanceBeginTime(res) {
				this.showFireMaintenanceBeginTime = false
				const date = new Date(res.value);
				const year = date.getFullYear();
				const month = String(date.getMonth() + 1).padStart(2, '0');
				const day = String(date.getDate()).padStart(2, '0');
				const formattedDate = `${year}-${month}-${day}`;

				let url = BASE_IP + "pc/presetfunction/update/fireMaintenanceBeginTime/" + this.preset.id + "/" +
					formattedDate
				uni.request({
					header: {
						"Authorization": this.user.token,
					},
					url: url,
					method: "POST",
					success: (res) => {
						if (res.statusCode == 200) {
							this.getPrall()
							return
						}
						if (res.statusCode == 404) {
							uni.showModal({
								title: "设置失败",
								icon: "error"
							})
							return
						}
						if (res.statusCode == 500) {
							uni.showModal({
								title: "设置失败",
								icon: "error"
							})
							return
						}
					}
				})
			},
			onFireMaintenanceExpirationTime(res) {
				this.showFireMaintenanceExpirationTime = false
				const date = new Date(res.value);
				const year = date.getFullYear();
				const month = String(date.getMonth() + 1).padStart(2, '0');
				const day = String(date.getDate()).padStart(2, '0');
				const formattedDate = `${year}-${month}-${day}`;

				let url = BASE_IP + "pc/presetfunction/update/fireMaintenanceExpirationTime/" + this.preset.id + "/" +
					formattedDate
				uni.request({
					header: {
						"Authorization": this.user.token,
					},
					url: url,
					method: "POST",
					success: (res) => {
						if (res.statusCode == 200) {
							this.getPrall()
							return
						}
						if (res.statusCode == 404) {
							uni.showModal({
								title: "设置失败",
								icon: "error"
							})
							return
						}
						if (res.statusCode == 500) {
							uni.showModal({
								title: "设置失败",
								icon: "error"
							})
							return
						}
					}
				})

			}
		}

	}
</script>

<style lang="scss" scoped>
	.btn80 {
		color: #fff;
		background-color: #49A0FF;
		padding: 14rpx 100rpx;
		border-radius: 8rpx;
		margin-bottom: 10rpx;
	}

	.fui-item__box {
		width: 100%;
		padding: 26rpx 32rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
	}

	.com_list_more {
		width: 170rpx;
		display: flex;
		align-items: center;
		justify-content: flex-end;
	}

	.com_list_more_icon {
		width: 40rpx;
		margin-left: 8rpx;
	}

	.canvas_box {
		position: fixed;
		left: 0;
		top: 0;
		z-index: 999;
		background: rgba(000, 000, 000, .5);
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

		.can_content {
			background: #fff;
			width: 80%;
			height: 60%;
			border-radius: 13rpx;
		}
	}

	.contents_ops {
		height: auto;
		width: 95%;
		margin: 25rpx auto;
		background-color: #fff;
		border: 1px solid #e4e7ed;
		border-radius: 18rpx;
	}

	.contents_ops_new {
		height: auto;
		width: 95%;
		margin: 25rpx auto;
		background-color: #fff;
		border: 1px solid #e4e7ed;
		border-radius: 18rpx;
	}

	.contents_fileman {
		// height: 860rpx;
		width: 95%;
		margin: 25rpx auto;

		border: 1px solid #e4e7ed;
		border-radius: 18rpx;
	}

	page {
		background-color: #f3f4f6;
	}

	.contents {
		width: 100%;
		height: 100%;
	}

	.contents-list {
		width: 98%;
		height: 100rpx;
		border-radius: 15rpx;
		margin: 25rpx auto;
		font-size: 12px;
	}

	.fireman-inpt {
		width: 90%;
		height: 200px;
		margin: auto;
	}

	.fireman-but {
		width: 100%;
	}

	.fireman-but-ok {
		width: 90%;
		height: 100rpx;
		margin: auto;
	}

	.signatures {
		width: 600rpx;
		height: 300px;
		margin: auto;
	}

	:deep(.font-color) {
		color: #303133;
		font-size: 28rpx;
	}

	.share_btn {
		margin: 0 !important;
		background: #49A0FF;
		padding: 18rpx 40rpx !important;
		font-size: 28rpx !important;
		border-radius: 9rpx !important;
	}

	.center {
		padding: 60rpx 0;
		text-align: center;
	}

	.ui-box {
		padding: 0 20rpx;
	}

	.ui-item {
		padding: 20rpx;
		line-height: 40rpx;
		color: #303133;
		font-size: 26rpx !important;
	}

	.ui-content {
		padding: 0 20rpx;
	}

	.add_user {
		position: fixed;
		right: 10rpx;
		bottom: 20%;
		border-radius: 50%;
		background: #49A0FF;
		color: #fff;
		width: 100rpx;
		height: 100rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		z-index: 999;
	}

	.line {
		border-bottom: 1rpx solid #e4e7ed;
	}

	.btn-list {
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		margin-bottom: 20rpx;
		padding: 0 10rpx;
		gap: 10rpx;
	}

	.slot-content-user-ops {
		padding-top: 20rpx;
	}

	.btn-box {
		display: flex;
		gap: 20rpx;
		justify-content: center;
		background: #fff;
		border-radius: 13rpx;
		padding: 0 40rpx;
	}
</style>